package com.cjkj.hospital.controller;

import com.cjkj.common.annotation.Log;
import com.cjkj.common.annotation.RepeatSubmit;
import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.core.page.TableDataInfo;
import com.cjkj.common.enums.BusinessType;
import com.cjkj.common.utils.poi.ExcelUtil;
import com.cjkj.hospital.domain.THospitalInfo;
import com.cjkj.hospital.domain.dto.HospitalDataReq;
import com.cjkj.hospital.domain.vo.HospitalExportVo;
import com.cjkj.hospital.domain.vo.HospitalDataVo;
import com.cjkj.hospital.service.ITHospitalInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 医院信息Controller
 * 
 * @author cjkj
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/hospital/info")
public class THospitalInfoController extends BaseController
{
    @Resource
    private ITHospitalInfoService tHospitalInfoService;

    /**
     * 查询医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalDataReq req) {
        startPage();
        List<HospitalDataVo> list = tHospitalInfoService.selectTHospitalInfoList(req);
        return getDataTable(list);
    }

    /**
     * 导出医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:info:export')")
    @Log(title = "医院信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalDataReq req) {
        List<HospitalExportVo> list = tHospitalInfoService.getExportInfoList(req);
        ExcelUtil<HospitalExportVo> util = new ExcelUtil<>(HospitalExportVo.class);
        util.exportExcel(response, list, "医院信息数据");
    }

    /**
     * 获取医院信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:info:query')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") String hospitalId)
    {
        return success(tHospitalInfoService.selectTHospitalInfoByHospitalId(hospitalId));
    }

    /**
     * 新增医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:info:add')")
    @Log(title = "医院信息", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PostMapping
    public AjaxResult add(@RequestBody THospitalInfo tHospitalInfo)
    {
        return toAjax(tHospitalInfoService.insertTHospitalInfo(tHospitalInfo));
    }

    /**
     * 修改医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:info:edit')")
    @Log(title = "医院信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PutMapping
    public AjaxResult edit(@RequestBody THospitalInfo tHospitalInfo)
    {
        return toAjax(tHospitalInfoService.updateTHospitalInfo(tHospitalInfo));
    }

    /**
     * 删除医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:info:remove')")
    @Log(title = "医院信息", businessType = BusinessType.DELETE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
	@DeleteMapping("/{hospitalIds}")
    public AjaxResult remove(@PathVariable String[] hospitalIds)
    {
        return success(tHospitalInfoService.deleteTHospitalInfoByHospitalIds(hospitalIds));
    }

    /**
     * 获取下拉框选项
     * @return
     */
    @GetMapping("getOptionData")
    public AjaxResult getOptionData(){
        return success(tHospitalInfoService.getOptionData());
    }
}
